{% extends "advbase.html" %}
{% block advcontent -%}
<form class="pure-form" action="" method="POST">
  <fieldset>
    <legend>{{_("Share")}}</legend>
    <p style="font-size:0.8em;color:grey;">
        {{_("Append hyperlinks for share to article.")}}
    </p>
    <div class="pure-control-group">
        <label for="enable_evernote" class="pure-checkbox">
            <input id="enable_evernote" name="evernote" type="checkbox" 
                {% if user and user.evernote %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(savetoevernote)}}
        </label>
        <input type="text" name="evernote_mail" style="width:280px" placeholder="Evernote Email" 
            value="{% if user and user.evernote_mail %}{{ user.evernote_mail }}{% endif %}" />
    </div>
    
    <div class="pure-control-group">
        <label for="enable_wiz" class="pure-checkbox">
            <input id="enable_wiz" name="wiz" type="checkbox" 
                {% if user and user.wiz %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(savetowiz)}}
        </label>
        <input type="text" name="wiz_mail" style="width:280px" placeholder="Wiz Email" 
            value="{% if user and user.wiz_mail %}{{ user.wiz_mail }}{% endif %}" />
    </div>
    <hr style="width:90%;color:silver;margin:1em auto;" />
    <div class="pure-control-group">
        <label for="enable_pocket" class="pure-checkbox">
            <input id="enable_pocket" name="pocket" type="checkbox" 
                {% if user and user.pocket and user.pocket_access_token %} checked="1" {% endif %}
                {% if user and not user.pocket_access_token %} disabled="1" {% endif %}
            />
            {{_("Append hyperlink '%s' to article")|format(savetopocket)}}&nbsp;&nbsp;&nbsp;&nbsp;
            {%if user and user.pocket_access_token -%}
            [<a href="/oauth2/pocket" style="text-decoration:none;color:silver;">{{_("Authorized")}}</a>]
            {%else -%}
            [<a href="/oauth2/pocket">{{_("Authorize")}}</a>]
            {%endif -%}
        </label>
    </div>
    <div class="pure-control-group">
        <label for="enable_instapaper" class="pure-checkbox">
            <input id="enable_instapaper" name="instapaper" type="checkbox" 
                {% if user and user.instapaper %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(savetoinstapaper)}}
        </label>
        <input type="text" name="instapaper_username" id="instapaper_username" placeholder="Email or Username" 
                value="{% if user and user.instapaper_username %}{{ user.instapaper_username }}{% endif %}" 
                onchange="notifyInstapaperVerify();" />
        <input type="password" name="instapaper_password" id="instapaper_password" placeholder="Password" 
                value="{% if user and user.instapaper_password %}{{ ke_decrypt(user.instapaper_password, user.secret_key or '') }}{% endif %}" 
                onchange="notifyInstapaperVerify();" />
        [<a href="#" id="averInstapaper" onclick="verifyInstapaper();return false;">{{_("Verify")}}</a>]
    </div>
    <hr style="width:90%;color:silver;margin:1em auto;" />
    <div class="pure-control-group">
        <label for="enable_xweibo" class="pure-checkbox">
            <input id="enable_xweibo" name="xweibo" type="checkbox" 
                {% if user and user.xweibo %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(shareonxweibo)}}
        </label>
        <label for="enable_tweibo" class="pure-checkbox">
            <input id="enable_tweibo" name="tweibo" type="checkbox" 
                {% if user and user.tweibo %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(shareontweibo)}}
        </label>
        <label for="enable_facebook" class="pure-checkbox">
            <input id="enable_facebook" name="facebook" type="checkbox" 
                {% if user and user.facebook %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(shareonfacebook)}}
        </label>
        <label for="enable_twitter" class="pure-checkbox">
            <input id="enable_twitter" name="twitter" type="checkbox" 
                {% if user and user.twitter %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(shareontwitter)}}
        </label>
        <label for="enable_tumblr" class="pure-checkbox">
            <input id="enable_tumblr" name="tumblr" type="checkbox" 
                {% if user and user.tumblr %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(shareontumblr)}}
        </label>
        <label for="enable_browser" class="pure-checkbox">
            <input id="enable_browser" name="browser" type="checkbox" 
                {% if user and user.browser %}checked="1"{% endif %} />
            {{_("Append hyperlink '%s' to article")|format(openinbrowser)}}
        </label>
        <label for="enable_qrcode" class="pure-checkbox">
            <input id="enable_qrcode" name="qrcode" type="checkbox" 
                {% if user and user.qrcode %}checked="1"{% endif %} />
            {{_("Append qrcode of url to article")}}
        </label>
    </div>
    <hr style="width:90%;color:silver;margin:1em auto;" />
    <label for="fuck_gfw" class="pure-checkbox">
        <input id="fuck_gfw" type="checkbox" name="fuckgfw" 
        {% if user and user.share_fuckgfw %}checked="1"{% endif %} >
        {{_("Fuck Gfw (For users in China)")}}
    </label>
    <button type="submit" class="pure-button pure-button-primary" style="margin-top:8px;">{{_("Save settings")}}</button>
  </fieldset>    
</form>
{% endblock -%}
{% block js %}
<script type="text/javascript">
    function notifyInstapaperVerify() {
        document.getElementById("averInstapaper").innerHTML = "{{_('Verify')}}";
    };
    function verifyInstapaper() {
        document.getElementById("averInstapaper").innerHTML = "{{_('Verifying')}}";
        var instauser = document.getElementById("instapaper_username").value;
        var instapass = document.getElementById("instapaper_password").value;
        ajax({url:"/verifyajax/instapaper", type: "POST", 
            data: {username: instauser, password: instapass},
            success: function (resp, xml) {
                if (resp.status != "ok") {
                    alert("Error:" + resp.status);
                    document.getElementById("averInstapaper").innerHTML = "{{_('Verify')}}";
                }
                else if (resp.correct == 1) {
                    alert("{{_('Congratulation : the username and password are correct.')}}");
                    document.getElementById("averInstapaper").innerHTML = "{{_('Verified')}}";
                } else {
                    alert("{{_('Unhappily : the username or password is incorrect!')}}");
                    document.getElementById("averInstapaper").innerHTML = "{{_('Verify')}}";
                }
                
            },
            fail: function (status) {
                alert("{{_('Error when verify the username and password for Instapaper. Status:')}}" + status);
                document.getElementById("averInstapaper").innerHTML = "{{_('Verify')}}";
            }
        });
    };
</script>
{% endblock %}